/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.yonsei.iwb.srf.server;

import edu.yonsei.iwb.sdt.datastructure.tree.DNode;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;

/**
 *
 * @author dk
 */
public class TestClient {

    public static void main(String[] args) {
        
        try {
            InetAddress host = InetAddress.getLocalHost();
            Socket socket = new Socket("165.132.123.181", 8080);
            PrintWriter pw = new PrintWriter(socket.getOutputStream());
            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));            
//            pw.println("select * from estest100 where f3 like 'o%e' limit 0, 30");
            pw.println("select * from estest100 where text=b group by f2, f3 limit 0, 5");
            pw.flush();
            
            
            
            
            
            String result = br.readLine();
            System.out.println(result);
            pw.close();
            br.close();
            socket.close();
        } catch (UnknownHostException ex) {
            Logger.getLogger(TestClient.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(TestClient.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    int slavenum = 1;
    int treenum = 3;
    String targetClass = "";
    String targetProperty = "";
    double refsr = 1.0;
    
    private void run(ArrayList<String> serverList, String tc, String tp, int tn, double refsr){
        
    }
    
    private void setRequest() throws IOException{
//        XContentParser jsonResult = JsonXContent.jsonXContent.createParser(request);
//            Map<String, Object> resultMap = jsonResult.mapOrdered();
////            ArrayList<LinkedHashMap> type = (ArrayList) resultMap.get("rows");
//            int slavenum = (int) resultMap.get("slave");
//            int treenum = (int) resultMap.get("treenum");
//            String targetClass = resultMap.get("tc").toString();
//            String targetProperty = resultMap.get("tp").toString();
//            double refsr = (double) resultMap.get("refsr");
//
//            System.out.println("#   slave : " + slavenum);
//            System.out.println("# treenum : " + treenum);
//            System.out.println("#   refsr : " + refsr);
        
//        XContentBuilder doc = XContentFactory.jsonBuilder().startObject();
//            doc.startObject("set");
//            doc.field("size", trees.size());
//            for (int i = 0; i < trees.size(); i++) {
//                DNode tree = trees.get(i);
//                doc.startObject("treeid");
//                addTreeToResult(tree, doc);
//                doc.endObject();
//            }
//            doc.endObject().endObject();
//            
//            
    }
}
